package bank

// 互斥锁实现bank

var (
	sema     = make(chan struct{}, 1) // a binary semaphore guarding balance
	balance2 int
)

func Deposit02(amount int) {
	sema <- struct{}{} // acquire token
	balance2 = balance2 + amount
	<-sema // release token

	// hello world
}

func Balance02() int {
	sema <- struct{}{} // acquire token
	b := balance2
	<-sema // release token
	return b
}
